#!/usr/bin/env bash

help(){
    cat<<__EOF__
Usage: m notificationcenter [OPTION]

Description: Manage the macOS Notification center

Options:
  --help     Show this help message
  --status   Show the current status of the notification Center
  --enable   Enable the notification Center
  --disable  Disable the notification Center
__EOF__
}

notification_center(){
    case $1 in
        --enable)
            launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
            killall NotificationCenter
            echo "Notification center enabled..."
            echo "Restart your computer for this to take effect"
            ;;
        --disable)
            echo "Enable notification center: NO"
            launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
            killall NotificationCenter
            echo "Notification center disabled..."
            echo "Restart your computer for this to take effect"
            ;;
        --status)
            ps -A | grep apsd | grep -v grep &>/dev/null
            if [ $? -eq 0 ]; then
                CENTER_STATUS="enabled"
            else
                CENTER_STATUS="disabled"
            fi
            echo "Notification Center: $CENTER_STATUS"
            ;;
        *)
            help && exit 1
            ;;
    esac
}

case $1 in
    --help)
        help
        ;;
    --enable|--disable|--status)
        notification_center "$@"
        ;;
    *)
        help && exit 1
        ;;
esac
